<{include file = "../include/header.html"}>

<div class="layout-breadcrumb">
	<ol class="breadcrumb">
		<li class="breadcrumb-item"><a href="<{url('index','index')}>">首页</a></li>
		<li class="breadcrumb-item active">登录</li>
	</ol>
</div>
<div class="layout-container">
	<div class="card">
		<div class="card-header">登录</div>
		<form class="card-body form">
			<div class="input-group mb-3">
				<div class="input-group-prepend">
					<span class="input-group-text">账　号</span>
				</div>
				<input type="text" class="form-control" name="account" placeholder="请输入你的用户名或邮箱"  required>
			</div>
			<div class="input-group mb-3">
				<div class="input-group-prepend">
					<span class="input-group-text">密　码</span>
				</div>
				<input type="password" class="form-control" name="password" placeholder="请输入密码" required>
			</div>
			<{if C('login_email_code')}>
			<div class="input-group mb-3">
				<div class="input-group-prepend">
					<span class="input-group-text">验证码</span>
				</div>
				<input type="number" class="form-control" name="code" placeholder="请输入邮箱验证码（发送至当前账号所绑定邮箱）"  required>
				<div class="input-group-append">
					<button class="btn btn-success" id="send">发送验证码</button>
				</div>
			</div>
			<{/if}>
			<div class="mb-3">
				<span>忘记密码了？<a href="<{url('user','forget')}>">找回密码</a></span>
			</div>
			<button type="submit" class="btn btn-primary btn-block">登录</button>
		</form> 
	</div>
</div>

<script>
<{if C('login_email_code')}>
$('#send').click(function() {
	var account = $('[name="account"]').val();
	if(! account) {
		HuajiBBS.tips('请输入账号！','warning');
		$('[name="account"]').focus();
		return;
	}
	
	$.post('<{url('user','email_code_ajax','login')}>',{account: account},function(data) {
		success: function(data) {
			HuajiBBS.tips(data.msg,'success');
			
			$('#send').attr('disabled','disabled').html('<span id="send-wait">120</span> 秒后重新发送');
			setInterval(function() {
				var wait = parseInt($('#send-wait').text());
				$('#send-wait').text(-- wait);
				if(wait == 0) {
					$('#send').removeAttr('disabled').text('重新发送');
				}
			},1000);
		}
	});
});
<{/if}>

HuajiBBS.submit('.form',function(data) {
	HuajiBBS.request('<{url('user','login_ajax')}>',data.field,{
		success: function(data) {
			HuajiBBS.tips('登录成功！跳转中…','success');
			window.location.href = '<{(strpos($smarty.server.HTTP_REFERER,'user/login') === false && strpos($smarty.server.HTTP_REFERER,'user/register') === false) ? $smarty.server.HTTP_REFERER : URL}>';
		}
	});
});
</script>

<{include file = "../include/footer.html"}>